package data;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import service.impl.ChatServiceImpl;

public class UserTable {
	
	private volatile Map<String,ChatServiceImpl> users;
	
	private volatile static UserTable userTable;
	
	
	private UserTable(){
		users = new ConcurrentHashMap<>();
	}
	
	public static UserTable getInstance(){
		if (userTable==null) {
			synchronized (UserTable.class) {
				if (userTable==null) {
					userTable = new UserTable();
				}
			}
		}
		return userTable;
	}
	
	public void add(ChatServiceImpl user){
		users.put(user.getServiceName(), user);
	}
	
	public ChatServiceImpl get(String username){
		return users.get(username);
	}
	
	public void remove(String name){
		users.remove(name);
	}
	
	public Map<String,ChatServiceImpl> getUers(){
		return users;
	}
	

}
